<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <script type="text/javascript" src="jquery.min.js"></script>

    <script>
        //获取当前登录用户邮箱显示到页面
        function init() {
            var token = getCookie("lagou_token");
            if (!token) {
                alert("token为空")
                return;
            }
            ;

            $.ajax({
                type: "GET",
                url: "http://www.test.com/api/user/info/" + token,
                dataType: "json",
                data: {},
                success: function (result) {
                    if (result.statusCode == 200) {
                        $("#email").text(result.data);
                    } else {
                        alert(result.statusText)
                    }
                },
                error: function (result) {
                    alert(result.statusText)
                }
            })
        }

        function getCookie(name){
            var strcookie = document.cookie;//获取cookie字符串
            var arrcookie = strcookie.split("; ");//分割
            //遍历匹配
            for ( var i = 0; i < arrcookie.length; i++) {
                var arr = arrcookie[i].split("=");
                if (arr[0] == name){
                    return arr[1];
                }
            }
            return "";
        }
    </script>
</head>
<body onload="init()" style="text-align: center">
<span id="email" name="email" style="text-align: center"></span>,欢迎登录系统
</body>
</html>